﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CRM.Database.Model.TechnicRequestsExt>" %>
<%--<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CRM.Models.TechnicRequestsExt>" %>--%>
<%@ Import Namespace="CRM.Resourses" %>

<%
    var customerEquipmentsCol = new CRM.Database.Model.CustomersEquipmentsCollection();
%>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdTechnicRequestsEquipments";
                                        settings.KeyFieldName = "IdEquipment";
                                        settings.CallbackRouteValues = new { Controller = "TD", Action = "TechnicRequestsEquipments", key = Model.Key };
                                        settings.SettingsPager.PageSize = 20;

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Equipment;
                                            column.FieldName = "EquipmentTypeNameLocalized";
                                            column.EditFormSettings.Visible = DefaultBoolean.False;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.EquipmentVendor;
                                            column.FieldName = "VendorNameExt";
                                            column.EditFormSettings.Visible = DefaultBoolean.False;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.EquipmentModel;
                                            column.FieldName = "ModelExt";
                                            column.EditFormSettings.Visible = DefaultBoolean.False;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.EquipmentCount;
                                            column.FieldName = "EquipmentCount";
                                            column.EditFormSettings.Visible = DefaultBoolean.False;
                                        });
                                        

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Equipment;
                                            column.FieldName = "IdEquipment";
                                            column.Visible = false;
                                            column.Width = 400;
                                            column.EditFormSettings.Visible = DefaultBoolean.True;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                comboBoxProperties.Width = 400;
                                                comboBoxProperties.DropDownStyle = DropDownStyle.DropDownList;
                                                comboBoxProperties.DataSource = customerEquipmentsCol.GetCustomersEquipmentsByCustomerId(Model.Request.IdCustomer);
                                                //comboBoxProperties.DataSource = DB.GetCustomersEquipmentsByCustomerId(Model.Request.IdCustomer);
                                                comboBoxProperties.ValueField = "IdEquipment";
                                                comboBoxProperties.ValueType = typeof(int);
                                                comboBoxProperties.Columns.Add("EquipmentTypeNameLocalized", Resourses.Equipment, Unit.Percentage(70));
                                                comboBoxProperties.Columns.Add("VendorNameExt", Resourses.EquipmentModel, Unit.Percentage(30));
                                            }
                                        });
                                        
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = false;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        settings.Width = 500;
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "TD", Action = "TechnicRequestsEquipmentsAdd", key = Model.Key };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "TD", Action = "TechnicRequestsEquipmentsDelete", key = Model.Key };
                                    }).Bind(Model.RequestsEquipmentsList).GetHtml();
%>
